//
//  KFDDateCard.m
//  KFD
//
//  Created by JIRENTIANXIANG on 7/11/15.
//  Copyright © 2015 kfd. All rights reserved.
//

#import "KFDDateCard.h"
#import "ui_config.h"
#import "NSDate+format.h"

@interface KFDDateCard ()

@property (weak, nonatomic) IBOutlet UILabel *dateLabel;
@property (weak, nonatomic) IBOutlet UILabel *weekdayLabel;

@end

@implementation KFDDateCard

-(void)setDate:(NSDate *)date
{
    _date=date;
    self.dateLabel.text=[date day];
    self.weekdayLabel.text=[date weekday];
}

-(void)setAction:(KFDDateCardAction)action
{
    _action=action;
    UITapGestureRecognizer* tapRecog=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped)];
    [self addGestureRecognizer: tapRecog];
}

-(void)tapped
{
    self.selected=YES;
    if (self.action) {
        self.action();
    }
}

-(void)setSelected:(BOOL)selected
{
    _selected=selected;
    [self updateColor];
}

-(void)updateColor;
{
    if (self.isSelected) {
        self.backgroundColor=KFD_RED;
        self.dateLabel.textColor=KFD_WHITE;
        self.weekdayLabel.textColor=KFD_WHITE;
    }else{
        self.backgroundColor=KFD_WHITE;
        self.dateLabel.textColor=KFD_LIGHT_GRAY;
        self.weekdayLabel.textColor=KFD_LIGHT_GRAY;
    }
}

@end
